/*
 * @Author: c
 * @Date: 2023-12-06 02:14:14
 * @LastEditTime: 2024-01-12 18:59:12
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\system\menus\entities\menu.entity.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Role } from "src/core/system/roles/entities/role.entity";
import { Column, Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn } from "typeorm";

@Entity("menu")
export class Menu {
    
    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        name: "parent_id",
        nullable: false,
        comment: '父菜单ID'
    })
    parentId: number

    @Column({
        name: "tree_path",
        nullable: true,
        default: null,
        comment: "父节点ID路径"
    })
    treePath: string; //父节点ID路径


    @Column({
        type: 'varchar',
        length: 64,
        nullable: false,
        default: ''
    })
    name: string; //菜单名称

    @Column({
        type:'tinyint',
        nullable:false,
        comment:'菜单类型(1:菜单 2:目录 3:外链 4:按钮 5:页面组件)'
    })
    type: number; //菜单类型(1:菜单 2:目录 3:外链 4:按钮 5:页面组件)

    @Column({
        type:'varchar',
        length:128,
        default:'',
        comment:'前端路由路径(浏览器地址栏路径)'
    })
    path: string; //前端路由路径(浏览器地址栏路径)

    @Column({
        type:'varchar',
        length:128,
        nullable:true,
        default:null,
        comment:'组件路径(vue页面完整路径，省略.vue后缀)'
    })
    component: string; //组件路径(vue页面完整路径，省略.vue后缀)

    @Column({
        nullable: true,
        default:null,
        comment:"权限标识"
    })
    perm: string; //权限标识

    @Column({
        nullable:false,
        default:1,
        comment:'显示状态(1-显示;0-隐藏)'
    })
    visible: number; //显示状态(1-显示;0-隐藏)

    @Column({
        default: 0,
        comment:'排序，默认0'
    })
    sort: number; //排序，默认0

    @Column({
        nullable:true,
        default:'',
        comment:'菜单图标'
    })
    icon: string; //菜单图标

    @Column({
        type:"varchar",
        length:128,
        nullable:true,
        default:null,
        comment:"跳转路径"
    })
    redirect: string; //跳转路径

    @Column({
        name: 'create_time',
        type: 'timestamp',
        nullable:true,
        default: () => 'CURRENT_TIMESTAMP',
    })
    createTime: Date; //创建时间

    @Column({
        name: 'update_time',
        type: 'timestamp',
        nullable:true,
        default: () => 'CURRENT_TIMESTAMP',
    })
    updateTime: Date; //更新时间

    @Column({
        type:'tinyint',
        name: "always_show",
        nullable:true,
        default: null
    })
    alwaysShow: number; //【目录】只有一个子路由是否始终显示(1:是 0:否)

    @Column({
        type:'tinyint',
        name: "keep_alive",
        nullable:true,
        default: null
    })
    keepAlive: number; //【菜单】是否开启页面缓存(1:是 0:否)


    @ManyToMany(() => Role, (role) => role.menus)
    // @JoinTable({
    //     name: "role_menu",
    //     joinColumn: {
    //         name: 'menu_id',  //生成的列名称
    //         referencedColumnName: 'id' //关联的原始列名称
    //     },
    //     inverseJoinColumn: {
    //         name: "role_id",
    //         referencedColumnName: "id"
    //     }
    // })
    role: Role[];

}
